package com.ying.rabbitmqspringbootproducer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: IdempotenceConfig
 * Package: com.ying.rabbitmqspringbootproducer.config
 * Description:
 *
 * @Author 刘英杰
 * @Create 2025/7/23 22:21
 * @Version 1.0
 */

@Configuration
public class IdempotenceConfig {

    public static final String EXCHANGE_IDEMPOTENCE_NAME = "idempotenceExchange";
    public static final String QUEUE_IDEMPOTENCE_NAME = "idempotenceQueue";

    @Bean
    public Exchange idempotenceExchange() {
        return ExchangeBuilder.directExchange(EXCHANGE_IDEMPOTENCE_NAME).durable(true).build();
    }

    @Bean
    public Queue idempotenceQueue() {
        return QueueBuilder.durable(QUEUE_IDEMPOTENCE_NAME).build();
    }

    @Bean
    public Binding BindingIdempotenceQueue(Exchange idempotenceExchange, Queue idempotenceQueue) {
        return BindingBuilder.bind(idempotenceQueue).to(idempotenceExchange).with("reduceStock").noargs();
    }
}
